﻿using System.Windows.Input;
using BHS.TFSChangsetAnalyser.Export;
using BHS.TFSChangsetAnalyser.Model;
using BHS.TFSChangsetAnalyser.ViewModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace BHS.TFSChangsetAnalyser.UnitTests
{
    [TestClass]
    public class ExportCommandTests
    {
        private ICommand _command;
        private IMainWindowViewModel _mockViewModel;
        private IExportFilenameProvider _stubFilenameProvider;
        private IChangesetInfoExporter _stubExporter;


        [TestInitialize]
        public void TestInitialise()
        {
            _mockViewModel = MockRepository.GenerateMock<IMainWindowViewModel>();
            _stubFilenameProvider = MockRepository.GenerateStub<IExportFilenameProvider>();
            _stubExporter = MockRepository.GenerateStub<IChangesetInfoExporter>();

            _command = new ExportCommand(_mockViewModel, _stubFilenameProvider, _stubExporter);
        }

        [TestMethod]
        public void CannotExecuteWithoutAnalysisResults()
        {
            // Arrange
            ChangesetAnalysisResults results = new ChangesetAnalysisResults();

            _mockViewModel.Expect(x => x.AnalysisResults).Return(results);
            
            // Act
            bool canExecute = _command.CanExecute(null);

            // Assert
            Assert.IsFalse(canExecute, "CanExecute should be false because the results are empty");
        }

        [TestMethod]
        public void CanExecuteWithPopulatedAnalysisResults()
        {
            // Arrange
            ChangesetAnalysisResults results = new ChangesetAnalysisResults();
            results.AddChangesetForAnalysis(new ChangesetInfo());

            _mockViewModel.Expect(x => x.AnalysisResults).Return(results);

            // Act
            bool canExecute = _command.CanExecute(null);

            // Assert
            Assert.IsTrue(canExecute, "CanExecute should be true because the results are populated with at least one changeset");
        }
    }
}
